package com.clayecloud.common.admin.controller;

import com.clayecloud.common.admin.services.UserService;
import com.clayecloud.common.entity.User;
import com.clayecloud.common.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/user")
@Api(tags = "用户管理模块")
public class AdminUserController {

    @Resource
    private UserService userService;

    @PostMapping("/insert")
    @ApiOperation("增加用户")
    public MessageUtil insertUser(User user){
        return userService.insertSelective(user);
    }

    @GetMapping("/delete")
    @ApiOperation("根据UserID删除用户")
    public MessageUtil deleteUser(Integer userId){
        return userService.deleteByPrimaryKey(userId);
    }

    @PutMapping("/update")
    @ApiOperation("更新用户信息")
    public MessageUtil updateUser(User user){
        return userService.updateByPrimaryKeySelective(user);
    }

    @GetMapping("/all")
    @ApiOperation("获取所有数据")
    public MessageUtil getAllUser(Integer size, Integer page){
        return userService.selectAll(size, page);
    }

}
